import java.util.Calendar;

public class Demo4_21 {
    //判断字符串是否是回文数
    public static boolean isPalindrome(String s) {
        s = s.toLowerCase();//将字符串全部转换为小写字母
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            while (left < right && !isCharacterNum(s.charAt(left))) {
                left++;
            }
            while (left < right && !isCharacterNum(s.charAt(right))) {
                right--;
            }
            //left下标是合法字符
            //right下标是合法字符
            if (s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            } else {
                return false;
            }
        }
        return true;
    }

    //判断是不是数字、字符 和字母字符
    private static boolean isCharacterNum(char ch) {
        if (Character.isDigit(ch) || Character.isLetter(ch)) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        String s = "A man, a plan, a canal: Panama";
        System.out.println(isPalindrome(s));
    }
}
